package cn.itrip.trade.config;

import cn.itrip.beans.dtos.Dto;
import cn.itrip.beans.dtos.InputDto;
import cn.itrip.beans.dtos.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:小伟
 * @Description:
 * @Date:2020/4/3 15:41
 **/
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String,Object> handlerException(){
        Map<String,Object> map = new HashMap<>();
        map.put("code",500);
        map.put("msg","系统繁忙，请稍后重试");
        return map;
    }

        /**
         * 拦截返回json数据格式的异常
         */
        @ResponseBody
        @ExceptionHandler(value = StateException.class)
        public Dto exceptionHandle(){
            return InputDto.error("当前操作失败,查看是否登陆!");
        }
}


















